package com.bluebench.bigul.service.resolver;

import com.bluebench.bigul.domain.Element;
import com.bluebench.bigul.domain.Element.Parameter;
import com.bluebench.bigul.exception.GraphicInitializationException;


public class ParameterResolver extends DefaultExpressionResolver{
	
	public ParameterResolver() throws GraphicInitializationException {
		if(!IS_INITIALIZED){
			super.resolve();
		}
	}
		
	@Override
	public void resolve() throws GraphicInitializationException {		
				
		String expression = tag.getExpression();	
		String type = tag.getType();
		boolean nested = ((Parameter)tag).isNested();
		System.out.println("P----->"+tag.getId());	
		
		if(type!=null && type.equalsIgnoreCase("collection")){
			Parameter  p = (Parameter)tag;
			p.setResolver(DefaultExpressionResolver.getInstance(COLLECTION_RESOLVER));
			p.resolve();
		}else if(nested){
			Parameter  p = (Parameter)tag;
			Element e = (Element)p.getValue();
			e.setResolver(DefaultExpressionResolver.getInstance(ELEMENT_RESOLVER));
			e.resolve();
		}
		
		if(expression!=null && validate(expression)){
			resolveExpression(expression);
		}
		
		
	}	

}
